﻿#region Copyright (c) Nicola Gallo All rights reserved.
/*
 * All rights reserved. Reproduction of trasmission of this file, or a portion thereof,
 * is forbidden without prior written permission of Nicola Gallo.
 * 
 * Author: Nicola Gallo
 * Date: 09/04/2011
 * 
 * */
#endregion
namespace PrismMVC.Shell
{
    //.NET References
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    //Microsoft References
    using Microsoft.Practices.Prism.Regions;

    //PrismMVC References.
    using PrismMVC.Shell.Containers;

    /// <summary>
    /// Defines a shell proxy class.
    /// </summary>
    public class ShellProxy : IShellProxy
    {
        //Constructors

        /// <summary>
        /// Creates a new instance of <see cref="ShellProxy"/>.
        /// </summary>
        /// <param name="registry">Registry instance.</param>
        /// <param name="regionManager">Region manager instance.</param>
        public ShellProxy(IRegionViewRegistry registry, IRegionManager regionManager)
        {
            if (registry == null)
            {
                throw new ArgumentNullException("Registry parameter can not be equals to null.");
            }
            else if (regionManager == null)
            {
                throw new ArgumentNullException("Region manager parameter can not be equals to null.");
            }
            this.RegionViewRegistry = registry;
            this.RegionManager = regionManager;
        }

        //Properties

        /// <summary>
        /// Gets the region view registry.
        /// </summary>
        protected IRegionViewRegistry RegionViewRegistry { get; private set; }

        /// <summary>
        /// Gets the region manager.
        /// </summary>
        protected IRegionManager RegionManager { get; private set; }

        //Methods

        /// <summary>
        /// Adds a new view.
        /// </summary>
        /// <param name="regionName"></param>
        /// <param name="view"></param>
        public void AddView(String regionName, IView view)
        {
            if ((!string.IsNullOrWhiteSpace(regionName)) && (view != null))
            {
                this.RegionManager.Regions[regionName].Add(view);   
            }
        }
    }
}